$(function(){
    $(".btn").click(()=>{
        let username = $("#username")[0].value;
        let pwd = $("#password")[0].value;
        let rem = $(".remember > input")[0].checked;
        $.ajax({
            url:'./php/register/login.php',
            method:'post',
            dataType:'json',
            data:{
                username,
                pwd
            }
        }).then(res=>{
            // console.log(res.data);
            if( res.status == 1 ){
                if( rem ){
                    setCookie( "id" , res.data['id'] ,7*3600*24);
                    setCookie( "username" , res.data['userName'] ,7*3600*24);
                    setCookie("ulevel",res.data['ulevel'],7*3600*24);
                } else {
                    setCookie( "id" , res.data['id']);
                    setCookie( "username" , res.data['userName']);
                    setCookie("ulevel",res.data['ulevel']);
                }
                if( res.data['ulevel'] == 3 ){
                    window.location.href = `./index.html` ;
                } else if ( res.data['ulevel'] == 6 ){
                    window.location.href = `./html/admin/index.html` ;
                } else if ( res.data['ulevel'] == 9 ){
                    window.location.href = `./html/admin/index.html?opId=1` ;
                }
            } else {
                alert(res['info']);
            }
        });
    });
});